package com.idealighter.game.core.dao.generate.mapper;

import com.idealighter.game.core.dao.generate.domain.PlayerMainDomain;
import com.idealighter.game.core.dao.generate.domain.PlayerMainDomainExample.Criteria;
import com.idealighter.game.core.dao.generate.domain.PlayerMainDomainExample.Criterion;
import com.idealighter.game.core.dao.generate.domain.PlayerMainDomainExample;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.jdbc.SQL;

public class PlayerMainDomainSqlProvider {

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table player_main
     *
     * @mbg.generated Tue Aug 14 14:13:21 CST 2018
     */
    public String countByExample(PlayerMainDomainExample example) {
        SQL sql = new SQL();
        sql.SELECT("count(*)").FROM("player_main");
        applyWhere(sql, example, false);
        return sql.toString();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table player_main
     *
     * @mbg.generated Tue Aug 14 14:13:21 CST 2018
     */
    public String deleteByExample(PlayerMainDomainExample example) {
        SQL sql = new SQL();
        sql.DELETE_FROM("player_main");
        applyWhere(sql, example, false);
        return sql.toString();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table player_main
     *
     * @mbg.generated Tue Aug 14 14:13:21 CST 2018
     */
    public String insertSelective(PlayerMainDomain record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("player_main");
        
        if (record.getSuperId() != null) {
            sql.VALUES("super_id", "#{superId,jdbcType=BIGINT}");
        }
        
        if (record.getPhone() != null) {
            sql.VALUES("phone", "#{phone,jdbcType=VARCHAR}");
        }
        
        if (record.getUnionId() != null) {
            sql.VALUES("union_id", "#{unionId,jdbcType=VARCHAR}");
        }
        
        if (record.getUserName() != null) {
            sql.VALUES("user_name", "#{userName,jdbcType=VARCHAR}");
        }
        
        if (record.getEmail() != null) {
            sql.VALUES("email", "#{email,jdbcType=VARCHAR}");
        }
        
        if (record.getPlayerName() != null) {
            sql.VALUES("player_name", "#{playerName,jdbcType=VARCHAR}");
        }
        
        if (record.getPassword() != null) {
            sql.VALUES("password", "#{password,jdbcType=VARCHAR}");
        }
        
        if (record.getReLoginCode() != null) {
            sql.VALUES("re_login_code", "#{reLoginCode,jdbcType=VARCHAR}");
        }
        
        if (record.getRecommendId() != null) {
            sql.VALUES("recommend_id", "#{recommendId,jdbcType=BIGINT}");
        }
        
        if (record.getRegisterType() != null) {
            sql.VALUES("register_type", "#{registerType,jdbcType=TINYINT}");
        }
        
        if (record.getTourist() != null) {
            sql.VALUES("tourist", "#{tourist,jdbcType=BIT}");
        }
        
        if (record.getType() != null) {
            sql.VALUES("type", "#{type,jdbcType=TINYINT}");
        }
        
        if (record.getOnline() != null) {
            sql.VALUES("online", "#{online,jdbcType=BIT}");
        }
        
        if (record.getIcon() != null) {
            sql.VALUES("icon", "#{icon,jdbcType=INTEGER}");
        }
        
        if (record.getExp() != null) {
            sql.VALUES("exp", "#{exp,jdbcType=BIGINT}");
        }
        
        if (record.getLevel() != null) {
            sql.VALUES("level", "#{level,jdbcType=INTEGER}");
        }
        
        if (record.getIngot() != null) {
            sql.VALUES("ingot", "#{ingot,jdbcType=BIGINT}");
        }
        
        if (record.getGold() != null) {
            sql.VALUES("gold", "#{gold,jdbcType=BIGINT}");
        }
        
        if (record.getSafeGold() != null) {
            sql.VALUES("safe_gold", "#{safeGold,jdbcType=BIGINT}");
        }
        
        if (record.getWinGold() != null) {
            sql.VALUES("win_gold", "#{winGold,jdbcType=BIGINT}");
        }
        
        if (record.getCedit() != null) {
            sql.VALUES("cedit", "#{cedit,jdbcType=BIGINT}");
        }
        
        if (record.getLottery() != null) {
            sql.VALUES("lottery", "#{lottery,jdbcType=BIGINT}");
        }
        
        if (record.getTransferReward() != null) {
            sql.VALUES("transfer_reward", "#{transferReward,jdbcType=BIGINT}");
        }
        
        if (record.getBankPwd() != null) {
            sql.VALUES("bank_pwd", "#{bankPwd,jdbcType=VARCHAR}");
        }
        
        if (record.getVipLevel() != null) {
            sql.VALUES("vip_level", "#{vipLevel,jdbcType=INTEGER}");
        }
        
        if (record.getVipEndTime() != null) {
            sql.VALUES("vip_end_time", "#{vipEndTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getLocked() != null) {
            sql.VALUES("locked", "#{locked,jdbcType=BIT}");
        }
        
        if (record.getChannelId() != null) {
            sql.VALUES("channel_id", "#{channelId,jdbcType=VARCHAR}");
        }
        
        return sql.toString();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table player_main
     *
     * @mbg.generated Tue Aug 14 14:13:21 CST 2018
     */
    public String selectByExample(PlayerMainDomainExample example) {
        SQL sql = new SQL();
        if (example != null && example.isDistinct()) {
            sql.SELECT_DISTINCT("id");
        } else {
            sql.SELECT("id");
        }
        sql.SELECT("super_id");
        sql.SELECT("phone");
        sql.SELECT("union_id");
        sql.SELECT("user_name");
        sql.SELECT("email");
        sql.SELECT("player_name");
        sql.SELECT("password");
        sql.SELECT("re_login_code");
        sql.SELECT("recommend_id");
        sql.SELECT("register_type");
        sql.SELECT("tourist");
        sql.SELECT("type");
        sql.SELECT("online");
        sql.SELECT("icon");
        sql.SELECT("exp");
        sql.SELECT("level");
        sql.SELECT("ingot");
        sql.SELECT("gold");
        sql.SELECT("safe_gold");
        sql.SELECT("win_gold");
        sql.SELECT("cedit");
        sql.SELECT("lottery");
        sql.SELECT("transfer_reward");
        sql.SELECT("bank_pwd");
        sql.SELECT("vip_level");
        sql.SELECT("vip_end_time");
        sql.SELECT("locked");
        sql.SELECT("channel_id");
        sql.FROM("player_main");
        applyWhere(sql, example, false);
        
        if (example != null && example.getOrderByClause() != null) {
            sql.ORDER_BY(example.getOrderByClause());
        }
        
        String tmp = "";
        if (example != null && example.getLimit() != null) {
            tmp = " limit " + example.getLimit().toString();
            if (example.getOffset() != null) {
                tmp = tmp + " offset " + example.getOffset().toString();
            }
        }
        return sql + tmp;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table player_main
     *
     * @mbg.generated Tue Aug 14 14:13:21 CST 2018
     */
    public String updateByExampleSelective(Map<String, Object> parameter) {
        PlayerMainDomain record = (PlayerMainDomain) parameter.get("record");
        PlayerMainDomainExample example = (PlayerMainDomainExample) parameter.get("example");
        
        SQL sql = new SQL();
        sql.UPDATE("player_main");
        
        if (record.getId() != null) {
            sql.SET("id = #{record.id,jdbcType=BIGINT}");
        }
        
        if (record.getSuperId() != null) {
            sql.SET("super_id = #{record.superId,jdbcType=BIGINT}");
        }
        
        if (record.getPhone() != null) {
            sql.SET("phone = #{record.phone,jdbcType=VARCHAR}");
        }
        
        if (record.getUnionId() != null) {
            sql.SET("union_id = #{record.unionId,jdbcType=VARCHAR}");
        }
        
        if (record.getUserName() != null) {
            sql.SET("user_name = #{record.userName,jdbcType=VARCHAR}");
        }
        
        if (record.getEmail() != null) {
            sql.SET("email = #{record.email,jdbcType=VARCHAR}");
        }
        
        if (record.getPlayerName() != null) {
            sql.SET("player_name = #{record.playerName,jdbcType=VARCHAR}");
        }
        
        if (record.getPassword() != null) {
            sql.SET("password = #{record.password,jdbcType=VARCHAR}");
        }
        
        if (record.getReLoginCode() != null) {
            sql.SET("re_login_code = #{record.reLoginCode,jdbcType=VARCHAR}");
        }
        
        if (record.getRecommendId() != null) {
            sql.SET("recommend_id = #{record.recommendId,jdbcType=BIGINT}");
        }
        
        if (record.getRegisterType() != null) {
            sql.SET("register_type = #{record.registerType,jdbcType=TINYINT}");
        }
        
        if (record.getTourist() != null) {
            sql.SET("tourist = #{record.tourist,jdbcType=BIT}");
        }
        
        if (record.getType() != null) {
            sql.SET("type = #{record.type,jdbcType=TINYINT}");
        }
        
        if (record.getOnline() != null) {
            sql.SET("online = #{record.online,jdbcType=BIT}");
        }
        
        if (record.getIcon() != null) {
            sql.SET("icon = #{record.icon,jdbcType=INTEGER}");
        }
        
        if (record.getExp() != null) {
            sql.SET("exp = #{record.exp,jdbcType=BIGINT}");
        }
        
        if (record.getLevel() != null) {
            sql.SET("level = #{record.level,jdbcType=INTEGER}");
        }
        
        if (record.getIngot() != null) {
            sql.SET("ingot = #{record.ingot,jdbcType=BIGINT}");
        }
        
        if (record.getGold() != null) {
            sql.SET("gold = #{record.gold,jdbcType=BIGINT}");
        }
        
        if (record.getSafeGold() != null) {
            sql.SET("safe_gold = #{record.safeGold,jdbcType=BIGINT}");
        }
        
        if (record.getWinGold() != null) {
            sql.SET("win_gold = #{record.winGold,jdbcType=BIGINT}");
        }
        
        if (record.getCedit() != null) {
            sql.SET("cedit = #{record.cedit,jdbcType=BIGINT}");
        }
        
        if (record.getLottery() != null) {
            sql.SET("lottery = #{record.lottery,jdbcType=BIGINT}");
        }
        
        if (record.getTransferReward() != null) {
            sql.SET("transfer_reward = #{record.transferReward,jdbcType=BIGINT}");
        }
        
        if (record.getBankPwd() != null) {
            sql.SET("bank_pwd = #{record.bankPwd,jdbcType=VARCHAR}");
        }
        
        if (record.getVipLevel() != null) {
            sql.SET("vip_level = #{record.vipLevel,jdbcType=INTEGER}");
        }
        
        if (record.getVipEndTime() != null) {
            sql.SET("vip_end_time = #{record.vipEndTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getLocked() != null) {
            sql.SET("locked = #{record.locked,jdbcType=BIT}");
        }
        
        if (record.getChannelId() != null) {
            sql.SET("channel_id = #{record.channelId,jdbcType=VARCHAR}");
        }
        
        applyWhere(sql, example, true);
        return sql.toString();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table player_main
     *
     * @mbg.generated Tue Aug 14 14:13:21 CST 2018
     */
    public String updateByExample(Map<String, Object> parameter) {
        SQL sql = new SQL();
        sql.UPDATE("player_main");
        
        sql.SET("id = #{record.id,jdbcType=BIGINT}");
        sql.SET("super_id = #{record.superId,jdbcType=BIGINT}");
        sql.SET("phone = #{record.phone,jdbcType=VARCHAR}");
        sql.SET("union_id = #{record.unionId,jdbcType=VARCHAR}");
        sql.SET("user_name = #{record.userName,jdbcType=VARCHAR}");
        sql.SET("email = #{record.email,jdbcType=VARCHAR}");
        sql.SET("player_name = #{record.playerName,jdbcType=VARCHAR}");
        sql.SET("password = #{record.password,jdbcType=VARCHAR}");
        sql.SET("re_login_code = #{record.reLoginCode,jdbcType=VARCHAR}");
        sql.SET("recommend_id = #{record.recommendId,jdbcType=BIGINT}");
        sql.SET("register_type = #{record.registerType,jdbcType=TINYINT}");
        sql.SET("tourist = #{record.tourist,jdbcType=BIT}");
        sql.SET("type = #{record.type,jdbcType=TINYINT}");
        sql.SET("online = #{record.online,jdbcType=BIT}");
        sql.SET("icon = #{record.icon,jdbcType=INTEGER}");
        sql.SET("exp = #{record.exp,jdbcType=BIGINT}");
        sql.SET("level = #{record.level,jdbcType=INTEGER}");
        sql.SET("ingot = #{record.ingot,jdbcType=BIGINT}");
        sql.SET("gold = #{record.gold,jdbcType=BIGINT}");
        sql.SET("safe_gold = #{record.safeGold,jdbcType=BIGINT}");
        sql.SET("win_gold = #{record.winGold,jdbcType=BIGINT}");
        sql.SET("cedit = #{record.cedit,jdbcType=BIGINT}");
        sql.SET("lottery = #{record.lottery,jdbcType=BIGINT}");
        sql.SET("transfer_reward = #{record.transferReward,jdbcType=BIGINT}");
        sql.SET("bank_pwd = #{record.bankPwd,jdbcType=VARCHAR}");
        sql.SET("vip_level = #{record.vipLevel,jdbcType=INTEGER}");
        sql.SET("vip_end_time = #{record.vipEndTime,jdbcType=TIMESTAMP}");
        sql.SET("locked = #{record.locked,jdbcType=BIT}");
        sql.SET("channel_id = #{record.channelId,jdbcType=VARCHAR}");
        
        PlayerMainDomainExample example = (PlayerMainDomainExample) parameter.get("example");
        applyWhere(sql, example, true);
        return sql.toString();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table player_main
     *
     * @mbg.generated Tue Aug 14 14:13:21 CST 2018
     */
    public String updateByPrimaryKeySelective(PlayerMainDomain record) {
        SQL sql = new SQL();
        sql.UPDATE("player_main");
        
        if (record.getSuperId() != null) {
            sql.SET("super_id = #{superId,jdbcType=BIGINT}");
        }
        
        if (record.getPhone() != null) {
            sql.SET("phone = #{phone,jdbcType=VARCHAR}");
        }
        
        if (record.getUnionId() != null) {
            sql.SET("union_id = #{unionId,jdbcType=VARCHAR}");
        }
        
        if (record.getUserName() != null) {
            sql.SET("user_name = #{userName,jdbcType=VARCHAR}");
        }
        
        if (record.getEmail() != null) {
            sql.SET("email = #{email,jdbcType=VARCHAR}");
        }
        
        if (record.getPlayerName() != null) {
            sql.SET("player_name = #{playerName,jdbcType=VARCHAR}");
        }
        
        if (record.getPassword() != null) {
            sql.SET("password = #{password,jdbcType=VARCHAR}");
        }
        
        if (record.getReLoginCode() != null) {
            sql.SET("re_login_code = #{reLoginCode,jdbcType=VARCHAR}");
        }
        
        if (record.getRecommendId() != null) {
            sql.SET("recommend_id = #{recommendId,jdbcType=BIGINT}");
        }
        
        if (record.getRegisterType() != null) {
            sql.SET("register_type = #{registerType,jdbcType=TINYINT}");
        }
        
        if (record.getTourist() != null) {
            sql.SET("tourist = #{tourist,jdbcType=BIT}");
        }
        
        if (record.getType() != null) {
            sql.SET("type = #{type,jdbcType=TINYINT}");
        }
        
        if (record.getOnline() != null) {
            sql.SET("online = #{online,jdbcType=BIT}");
        }
        
        if (record.getIcon() != null) {
            sql.SET("icon = #{icon,jdbcType=INTEGER}");
        }
        
        if (record.getExp() != null) {
            sql.SET("exp = #{exp,jdbcType=BIGINT}");
        }
        
        if (record.getLevel() != null) {
            sql.SET("level = #{level,jdbcType=INTEGER}");
        }
        
        if (record.getIngot() != null) {
            sql.SET("ingot = #{ingot,jdbcType=BIGINT}");
        }
        
        if (record.getGold() != null) {
            sql.SET("gold = #{gold,jdbcType=BIGINT}");
        }
        
        if (record.getSafeGold() != null) {
            sql.SET("safe_gold = #{safeGold,jdbcType=BIGINT}");
        }
        
        if (record.getWinGold() != null) {
            sql.SET("win_gold = #{winGold,jdbcType=BIGINT}");
        }
        
        if (record.getCedit() != null) {
            sql.SET("cedit = #{cedit,jdbcType=BIGINT}");
        }
        
        if (record.getLottery() != null) {
            sql.SET("lottery = #{lottery,jdbcType=BIGINT}");
        }
        
        if (record.getTransferReward() != null) {
            sql.SET("transfer_reward = #{transferReward,jdbcType=BIGINT}");
        }
        
        if (record.getBankPwd() != null) {
            sql.SET("bank_pwd = #{bankPwd,jdbcType=VARCHAR}");
        }
        
        if (record.getVipLevel() != null) {
            sql.SET("vip_level = #{vipLevel,jdbcType=INTEGER}");
        }
        
        if (record.getVipEndTime() != null) {
            sql.SET("vip_end_time = #{vipEndTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getLocked() != null) {
            sql.SET("locked = #{locked,jdbcType=BIT}");
        }
        
        if (record.getChannelId() != null) {
            sql.SET("channel_id = #{channelId,jdbcType=VARCHAR}");
        }
        
        sql.WHERE("id = #{id,jdbcType=BIGINT}");
        
        return sql.toString();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table player_main
     *
     * @mbg.generated Tue Aug 14 14:13:21 CST 2018
     */
    protected void applyWhere(SQL sql, PlayerMainDomainExample example, boolean includeExamplePhrase) {
        if (example == null) {
            return;
        }
        
        String parmPhrase1;
        String parmPhrase1_th;
        String parmPhrase2;
        String parmPhrase2_th;
        String parmPhrase3;
        String parmPhrase3_th;
        if (includeExamplePhrase) {
            parmPhrase1 = "%s #{example.oredCriteria[%d].allCriteria[%d].value}";
            parmPhrase1_th = "%s #{example.oredCriteria[%d].allCriteria[%d].value,typeHandler=%s}";
            parmPhrase2 = "%s #{example.oredCriteria[%d].allCriteria[%d].value} and #{example.oredCriteria[%d].criteria[%d].secondValue}";
            parmPhrase2_th = "%s #{example.oredCriteria[%d].allCriteria[%d].value,typeHandler=%s} and #{example.oredCriteria[%d].criteria[%d].secondValue,typeHandler=%s}";
            parmPhrase3 = "#{example.oredCriteria[%d].allCriteria[%d].value[%d]}";
            parmPhrase3_th = "#{example.oredCriteria[%d].allCriteria[%d].value[%d],typeHandler=%s}";
        } else {
            parmPhrase1 = "%s #{oredCriteria[%d].allCriteria[%d].value}";
            parmPhrase1_th = "%s #{oredCriteria[%d].allCriteria[%d].value,typeHandler=%s}";
            parmPhrase2 = "%s #{oredCriteria[%d].allCriteria[%d].value} and #{oredCriteria[%d].criteria[%d].secondValue}";
            parmPhrase2_th = "%s #{oredCriteria[%d].allCriteria[%d].value,typeHandler=%s} and #{oredCriteria[%d].criteria[%d].secondValue,typeHandler=%s}";
            parmPhrase3 = "#{oredCriteria[%d].allCriteria[%d].value[%d]}";
            parmPhrase3_th = "#{oredCriteria[%d].allCriteria[%d].value[%d],typeHandler=%s}";
        }
        
        StringBuilder sb = new StringBuilder();
        List<Criteria> oredCriteria = example.getOredCriteria();
        boolean firstCriteria = true;
        for (int i = 0; i < oredCriteria.size(); i++) {
            Criteria criteria = oredCriteria.get(i);
            if (criteria.isValid()) {
                if (firstCriteria) {
                    firstCriteria = false;
                } else {
                    sb.append(" or ");
                }
                
                sb.append('(');
                List<Criterion> criterions = criteria.getAllCriteria();
                boolean firstCriterion = true;
                for (int j = 0; j < criterions.size(); j++) {
                    Criterion criterion = criterions.get(j);
                    if (firstCriterion) {
                        firstCriterion = false;
                    } else {
                        sb.append(" and ");
                    }
                    
                    if (criterion.isNoValue()) {
                        sb.append(criterion.getCondition());
                    } else if (criterion.isSingleValue()) {
                        if (criterion.getTypeHandler() == null) {
                            sb.append(String.format(parmPhrase1, criterion.getCondition(), i, j));
                        } else {
                            sb.append(String.format(parmPhrase1_th, criterion.getCondition(), i, j,criterion.getTypeHandler()));
                        }
                    } else if (criterion.isBetweenValue()) {
                        if (criterion.getTypeHandler() == null) {
                            sb.append(String.format(parmPhrase2, criterion.getCondition(), i, j, i, j));
                        } else {
                            sb.append(String.format(parmPhrase2_th, criterion.getCondition(), i, j, criterion.getTypeHandler(), i, j, criterion.getTypeHandler()));
                        }
                    } else if (criterion.isListValue()) {
                        sb.append(criterion.getCondition());
                        sb.append(" (");
                        List<?> listItems = (List<?>) criterion.getValue();
                        boolean comma = false;
                        for (int k = 0; k < listItems.size(); k++) {
                            if (comma) {
                                sb.append(", ");
                            } else {
                                comma = true;
                            }
                            if (criterion.getTypeHandler() == null) {
                                sb.append(String.format(parmPhrase3, i, j, k));
                            } else {
                                sb.append(String.format(parmPhrase3_th, i, j, k, criterion.getTypeHandler()));
                            }
                        }
                        sb.append(')');
                    }
                }
                sb.append(')');
            }
        }
        
        if (sb.length() > 0) {
            sql.WHERE(sb.toString());
        }
    }
}